﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Medianamik.UI.Controls;

namespace Medianamik.UI
{
    public class EditButton : LockButton
    {
        //private const string LOCKED_OR_DISABLED_IMAGE_URL = "/Medianamik/images/Icones/Ico_EditionInactif.gif";
        //private const string EDIT_IMAGE_URL = "/Medianamik/images/Icones/Ico_Edition.gif";
        //private const string ADD_IMAGE_URL = "/Medianamik/images/Icones/Ico_Plus.gif";
        //private static readonly MedianamikConfigSection _config = (MedianamikConfigSection)ConfigurationManager.GetSection(ConfigurationSectionName.MEDIANAMIK);

        //private CultureInfo _editionCulture;
        //private WebSite _webSite;
        //private bool HasWebSite
        //{
        //    get { return _webSite != null; }
        //}

        //public void Configure(LockButton pButton, Node pNode)
        //{
        //    pButton.LockedOrDisabledImageUrl = LOCKED_OR_DISABLED_IMAGE_URL;
        //    pButton.ImageUrl = GetEditImageUrl(pNode);
        //    pButton.Enabled = EditButtonEnabled(pNode);
        //    pButton.NodeId = pNode.ID;

        //    if (_config.EnableMultiLanguageFeatures &&
        //        ((UserProfile)HttpContext.Current.Profile).EnableMultiLanguageFeatures &&
        //        !pNode.HasInstanceForCurrentEditionCulture &&
        //        !pNode.IsLanguageNeutral)
        //    {
        //        pButton.NavigateUrl = "";
        //        pButton.OnClientRequestSucceeded =
        //            "radopen('/medianamik/modalwindows/CultureSelectorWindow.aspx?nodeid=" + pNode.ID + "', 'CultureSelectorWindow');";
        //    }
        //}

        //protected string GetEditImageUrl(Node pNode)
        //{
        //    string imageUrl = pNode.HasInstanceForCurrentEditionCulture || pNode.IsLanguageNeutral
        //                          ? EDIT_IMAGE_URL
        //                          : ADD_IMAGE_URL;
        //    return imageUrl;
        //}

        //protected bool EditButtonEnabled(Node pNode)
        //{
        //    //Pour les Noeuds avec une URL, il faut que le Website soit traduit dans la langue en cours
        //    bool hasUrl = false;
        //    if (NodeTypeHasUrl.ContainsKey(pNode.NodeTypeID))
        //    {
        //        hasUrl = NodeTypeHasUrl[pNode.NodeTypeID];
        //    }
        //    else
        //    {
        //        var nodeType = NodeTypeManager.GetNodeType(pNode.NodeTypeID);
        //        hasUrl = nodeType.GetAllProperties().Any(p => string.Equals(p.Name, "Url", StringComparison.OrdinalIgnoreCase));
        //        NodeTypeHasUrl.Add(pNode.ID, hasUrl);
        //    }

        //    if (!HasWebSite) { return true; }

        //    bool websiteInstanceExists = HasWebSite
        //                                 && _webSite.Instances.Exists(_editionCulture);
        //    bool editEnabled = hasUrl
        //                           ? websiteInstanceExists ? true : false
        //                           : true;

        //    return editEnabled;
        //}
    }
}
